<template>
      <div class="main">
            <div class="topBackground">
                <a href="index.html" >首页</a>
                <i data-v-61679c2b="" aria-label="icon: right" class="anticon anticon-right"><svg viewBox="64 64 896 896" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></i>
                <span>视频详情</span>
            </div>

            <div class="box">
                <div class="title">
                        <div class="collect">
                            <img src="" alt="">
                            <div>收藏</div>
                        </div>
                        <div class="title-img">
                              <img :src="courseDetail.bannerFileUrl" alt="">
                        </div>
                        <div class="detail">
                              <h2>{{courseDetail.courseTitle}}</h2>
                            <div class="rating">
                                <p>累计{{courseDetail.participationsCount}}人学习</p>
                                <span>★</span><span>★</span><span>★</span><span>★</span><span>★</span>
                            </div>
                            <div  class="detail-price-info">
                                <div class="detail-price-box">
                                 <div class="detail-free-font" v-if="courseDetail.isFree == 1">免费</div>
                                    <div class="detail-new-price" v-else-if="courseDetail.isDiscount == 1">￥{{ courseDetail.discountPrice }} </div>
                                    <div class="detail-old-price" v-else-if="courseDetail.isDiscount == 0">￥{{ courseDetail.coursePrice }}</div>
                            </div>
                            <span class="detail-time-limit" v-if="courseDetail.isFree == 0 && courseDetail.isDiscount == 1">限时钜惠</span>
                            </div>
                            <div class="actions">
                                <button class="watch-now">立即观看</button>
                                <button class="add-to-cart">加入购物车</button>
                            </div>
                        </div>
                  </div>
                <div class="content">
                  <div class="tab">
                          <div class="tab_top">
                              <ul>
                                <li :class="{current: currentTab === 'courseDesc'}" @click="currentTab = 'courseDesc'">课程描述</li>
                                <li :class="{current: currentTab === 'catalog'}" @click="currentTab = 'catalog'">目录</li>
                                <li :class="{current: currentTab === 'comment'}" @click="currentTab = 'comment'">评论</li>
                              </ul>
                          </div>
                          <div class="tab_bottom">
                            
                              <div class="item detailFont" v-show="currentTab === 'courseDesc'" v-html="courseDetail.courseDetail">
                                   
                              </div>
                              <div class="item" v-show="currentTab === 'catalog'">
                                <div class="container" v-for="(item, index) in courseDetail.sections" :key="item.sectionId">
                                      <div class="catalog">
                                            <div class="catalog-top">
                                                <p>{{ index + 1 }}. {{ item.sectionName }}</p>
                                                <div class="download">                
                                                    <div class="download-icon"><i data-v-3a7480b1="" aria-label="icon: cloud-download" class="anticon anticon-cloud-download"><svg viewBox="64 64 896 896" data-icon="cloud-download" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M624 706.3h-74.1V464c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v242.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.7a8 8 0 0 0 12.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9z"></path><path d="M811.4 366.7C765.6 245.9 648.9 160 512.2 160S258.8 245.8 213 366.6C127.3 389.1 64 467.2 64 560c0 110.5 89.5 200 199.9 200H304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8h-40.1c-33.7 0-65.4-13.4-89-37.7-23.5-24.2-36-56.8-34.9-90.6.9-26.4 9.9-51.2 26.2-72.1 16.7-21.3 40.1-36.8 66.1-43.7l37.9-9.9 13.9-36.6c8.6-22.8 20.6-44.1 35.7-63.4a245.6 245.6 0 0 1 52.4-49.9c41.1-28.9 89.5-44.2 140-44.2s98.9 15.3 140 44.2c19.9 14 37.5 30.8 52.4 49.9 15.1 19.3 27.1 40.7 35.7 63.4l13.8 36.5 37.8 10C846.1 454.5 884 503.8 884 560c0 33.1-12.9 64.3-36.3 87.7a123.07 123.07 0 0 1-87.6 36.3H720c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h40.1C870.5 760 960 670.5 960 560c0-92.7-63.1-170.7-148.6-193.3z"></path></svg></i></div>
                                                    <div class="download-text">下载</div>
                                                </div>
                                            </div>
                                            <div class='sectionName${index} catalog-content'>
                                                 <div class="section" v-for="(subItem, subIndex) in item.subSections" :key="subItem.sectionId">
                                                        <div class="section-title">{{ index + 1 }}-{{ subIndex + 1 }}. {{ subItem.sectionName }}</div>
                                                        <div class="section-action">
                                                            <span>
                                                            <span  class="play-icon"><i><svg viewBox="64 64 896 896" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M719.4 499.1l-296.1-215A15.9 15.9 0 0 0 398 297v430c0 13.1 14.8 20.5 25.3 12.9l296.1-215a15.9 15.9 0 0 0 0-25.8zm-257.6 134V390.9L628.5 512 461.8 633.1z"></path></svg></i>
                                                            </span>
                                                            <span data-v-3a7480b1="" class="play-text"> 观看 </span>
                                                            </span>
                                                        </div>
                                                        
                                                    </div>
                                            </div>
                                        </div>
                                </div> 
                              </div>

                              <div class="item" v-show="currentTab === 'comment'">
                                <!-- 评论内容 -->
                                <div class="comment-section">
                                    <h2>评论</h2>
                                    <div class="rating">
                                        <span class="rating-star">★</span>
                                        <span class="rating-star">★</span>
                                        <span class="rating-star">★</span>
                                        <span class="rating-star">★</span>
                                        <span class="rating-star">★</span>
                                        <span class="rating-text">非常好</span>
                                    </div>
                                    <textarea placeholder="请发表您对课程的评价"></textarea>
                                    <button class="submit-button">发表评论</button>
                                    <div class="comments" id="othersComments">
                                        <div class="comments-container">
                                            <!-- 评论 -->
                                            <div v-for="(item) in commentList" :key="item.commentId" class="commentsItem">
                                               
                                                <div class="comments-info">
                                                    <div>
                                                        <img :src="item.user.avatarUrl" alt="">
                                                        <span>{{ item.user.nickname }}</span>
                                                    </div>
                                                    <div class="star-level">
                                                        <svg v-for="num in 5" :key="num" viewBox="64 64 896 896" data-icon="star" width="20"
                                                            height="20" fill="rgb(250, 219, 20)" aria-hidden="true" focusable="false" class="">
                                                            <path
                                                                d="M908.1 353.1l-253.9-36.9L540.7 86.1c-3.1-6.3-8.2-11.4-14.5-14.5-15.8-7.8-35-1.3-42.9 14.5L369.8 316.2l-253.9 36.9c-7 1-13.4 4.3-18.3 9.3a32.05 32.05 0 0 0 .6 45.3l183.7 179.1-43.4 252.9a31.95 31.95 0 0 0 46.4 33.7L512 754l227.1 119.4c6.2 3.3 13.4 4.4 20.3 3.2 17.4-3 29.1-19.5 26.1-36.9l-43.4-252.9 183.7-179.1c5-4.9 8.3-11.3 9.3-18.3 2.7-17.5-9.5-33.7-27-36.3z">
                                                            </path>
                                                        </svg>
                                                    </div>
                                                </div>
                                              
                                                <div class="comments-content">
                                                    <p>{{ item.commentContent }}</p>
                                                    <div>
                                                        <span class="remark-date">{{ item.createdTime }}</span>
                                                        <span>回复</span>
                                                    </div>
                                                </div>

                                                <div class="comment-reply" v-for="reply in item.subCommentList" :key="reply.commentId">
                                                    <div class="comment-header">
                                                        <img :src="reply.user.avatarUrl" alt="Avatar">
                                                        <span class="username">{{ reply.user.nickname }}</span>
                                                        <span>&nbsp;&nbsp;回复&nbsp;</span>
                                                        <span>{{ reply.parentUserName }}:&nbsp;&nbsp;</span>
                                                        <span>{{ reply.commentContent }}</span>
                                                        
                                                    </div>
                                                    <div style="margin-right: 10px;">
                                                        <span class="reply-date" >{{ reply.createdTime }}</span>
                                                    </div>
                                                </div>
                                            </div>
         
                                        </div>
                                    </div>
                                </div>
                            </div>
                            </div>
                </div>
                </div>
            
            </div>
      </div>
</template>

<script>
import { getCourseDetail ,getComment} from '@/api/request'

export default {
    name: 'contentView',
    data() {
        return {
            
            courseDetail: {
                courseId: '' // 设置初始值
            },
            commentList: [],
            currentTab: 'courseDesc' // 添加Tab状态变量
            ,
            
            
        }
    },
    created() {
        console.log(this.$route.query.id)   
        getCourseDetail(this.$route.query.id).then(res => {

          this.courseDetail = res.data // 假设响应数据在 res.data 中

        }).catch(err => {
          console.error('获取课程详情失败:', err)
        })
        getComment(this.$route.query.id).then(res => {
            console.log("获取评论成功")
            console.log(res.rows)
            this.commentList = res.rows
        }).catch(err => {
          console.error('获取评论失败:', err)
        })
        
    }
}
</script>
<style lang="scss" scoped>
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
/* main */
.main{
    width: 100%;
    height: 100%;
    background: #f5f5f5;
    .topBackground{
        font-size: 16px;
        padding: 20px 0 15px 20px;
        margin: auto;
        color: #fff;
        width: 1200px;
        height: 164px;
        background-size: 100%;
        background: linear-gradient(90deg, #5782f6, #4683ff);
        box-shadow: 0 8px 10px 0 rgba(40, 113, 234, .1);
        a{
            color: #fff;
            text-decoration: none;
        }
    }
}
.box {
    width: 1160px;
    margin: auto;
    .title{
        width: 100%;
        position: relative;
        background: #fff;
        border-radius: 4px;
        height: 280px;
        margin-top: -100px;
        box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);
        display: flex;
        margin-bottom: 20px;
        .collect{
            cursor: pointer;
            width: 110px;
            height: 30px;
            font-size: 16px;
            display: flex;
            flex-direction: column;
            align-items: center;
            float: right;
            color: #999;
            position: absolute;
            right: 30px;
            top: 30px;
            &:hover{
                color: #c8ff00;
            }
        }
        .title-img{
            box-sizing: border-box;
            width: 33.33333333%;
            height: 220px;
            margin-top: 20px;
            margin-left: 30px;
            
        }
        .title-img>img{
            width: 330px;
            height: 220px;
            border-radius: 12px;
        }
       
    }

    .detail {
        padding: 10px;
        flex: 1;
    }
    
    .detail h2 {
        font-size: 24px;
        font-weight: 400;
        margin: 15px 0 15px;
    }
    
    .detail p {
        font-size: 14px;
        margin: 5px 5px;
        color: #a3a3a3;

    }
    
    .detail>.price{
        font-size: 22px;
        font-weight: bold;
        color: red;
        .vip>img{
            width: 66px;
            height: 20px;
            margin-left: 5px
        }
    }

    .rating{
        font-size: 24px;
        color: #ffcc00;
        display: flex;
        align-items: center;
    }
    
    
    .rating span {
        margin-right: 3px;
    }
    
    .price {
        color: #e91e63;
        font-size: 18px;
        margin: 10px 0;
    }
    
    .vip {
        color: #999;
        font-size: 12px;
        margin-left: 5px;
    }
    
    .actions {
        position: absolute;
        display: flex;
        bottom: 30px;
    }
    
    .watch-now, .add-to-cart {
        border: none;
        cursor: pointer;
        width: 121px;
        height: 40px;
        font-size: 18px;
        border-radius: 24px;
        margin-right: 15px;
        
    }
    
    .watch-now {
        background-color: #00bfa5;
        color: white;
    }
    
    .add-to-cart {
        background-color: #f9d8e4;
        color: rgb(243, 35, 69);
    }

    .content{
        width: 100%;
        margin-top: 20px;
        background: #fff;
        border-radius: 4px;
        height: auto;
    }
}
/* tap */
.tab_top ul {
    display: block;
    list-style: none;
    padding: 0;
    margin: 5px auto;
    text-align: center;
    width: 1160px;
    border-bottom: 1px solid #ccc;
    margin-bottom: 10px;
    box-sizing: border-box;
    font-size: 16px;
    font-weight: 400;
  }
  .tab_top li {
    display: inline-block;
    padding: 10px;
    cursor: pointer;
  }
  .tab_top .current {
    color: #00cf8c;
    border-bottom: 2px solid #00cf8c;
  }
  /* 移除或注释以下样式 */
  /*
  .tab_bottom .item { display: none; }
  .tab_bottom .item:first-child { display: block; }
  */
#courseDetail>p{
    color: rgb(113, 111, 111);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    font-size: 14px;
    white-space-collapse: preserve;
    word-wrap: break-word;
    line-height: 1.5;
    margin: 20px 0;
    padding: 0 30px;
  }
  
/* 评论 */
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f9f9f9;
}

.comment-section {
    width: 95%;
    margin: 20px auto;
    background-color: #fff;
    padding: 20px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.comment-section h2 {
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 200;
    color: #6a6868;
}

.rating {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.rating>.rating-star {
    color: #ffcc00;
    margin-right: 5px;
}
.rating-text{
    font-weight: 200;
    font-size: 14px;
    color: #6a6868;
    margin-left: 8px;
    margin-top:5px;
}

textarea {
    width: 100%;
    height: 100px;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: none;
}

.submit-button {
    float: right;
    padding: 10px 20px;
    background-color: #00cc66;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    overflow: hidden;
}

.submit-button:hover {
    background-color: #00b35b;
}

.comments {
    margin-top: 60px;
}

.comment {
    border-top: 1px solid #ddd;
    padding-top: 10px;
    margin-top: 10px;
    height: auto;
}

.comment-header {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}

.comment-header img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 10px;
}

.comment-header .username {
    font-weight: bold;
}

.comment-header .rating {
    margin-left: auto;
    color: #ffcc00;
}

.comment-body {
    position: relative;
    margin-bottom: 10px;
   
    a{
        text-decoration: none;
    }
    .date{
        position: absolute;
        right: 30px;
        bottom: 0;
        font-size: 12px;
        color: #6a6868;
    }
   .reply{
        font-size: 12px;
        position: absolute;
        right: 0;
        bottom: 0px;
        color: #6a6868;
        
   }
}

.comment-body p {
    margin: 0;
    
}

.comment-reply {
    border-left: 2px solid #ddd;
    padding-left: 10px;
    margin-left: 50px;
}

/* 目录详情  catalog*/
.catalog{
    font-size: 20px;
    padding: 5px 0 5px 10px;
    
}
.catalog-top{
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    margin-left: 30px;
    p{
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .download{
        box-sizing: border-box;
        margin-right: 28px;
        padding: 0 5px;
        white-space: nowrap;
        border-radius: 2px;
        //背景颜色
        background-color: rgb(45, 183, 245);
        cursor: pointer;
        display: flex;
    }
    .download-icon{
        height: 30px;
        width: 20px;
        text-align: center;
        display: block;
    }
    .download-text{
        float:right;
        height: 30px;
        line-height: 27px;
        width: 50px;
        text-align: center;
        display: block;
        font-size: 14px;
        color: #ffffff;
    }
}
.section{
    height: auto;
    line-height: 30px;
    padding: 10px 20px;
    background: #f2f2f2;
    margin: 10px 25px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    .section-title{
        font-size: 13px;
        font-weight: 400;
        color: #646363;
        
    }
    .section-action{
        
        cursor: pointer;
        .play-text{
            display: none;
        }
    }
}


/* footer 底部 */
footer{
    background: #0f141a;
    color: #777878;
    font-size: 14px;
    height: 197px;
    .friend-link{
        width: 51%;
        color: #fff;
        font-size: 22px;
        margin: 50px auto;
    }
    .box div{
        line-height: 30px;
    }
    .center{
       margin-bottom: 30px;
    }
    .box>div>a{
        margin-right: 30px;
        text-decoration: none;
        color:#777878;
    }
    .box>div>a:hover{
        color: #41f405;
    }
    .company{
        margin: 0 auto;
        width: 60%;
        border-top: #777878 solid 1px;
        text-align: center;
    }
}
.detail-price-info {
                    display: flex;
                    flex-direction: column;
}
.detail-price-box {
                        display: flex;
                        align-items: center;
                        .detail-free-font {
                            color: rgb(0, 207, 140);
                            font-size: 26px;
                            font-weight: 600;
                        }
                        .detail-new-price {
                            font-size: 26px;
                            font-weight: 600;
                            color: #f32425;
                        }
                        .detail-old-price {
                            font-weight: 500;
                            color: #b7bbc4;
                            font-size: 14px;
                            text-decoration: line-through;
                            margin: 0 10px;
                        }
                    }

 .detail-time-limit {
                margin-top: 15px;
                width: 80px;
                padding-left: 5px;
                background: linear-gradient(48deg, #fe26b8, #f7283f 23%, #fc3d3f 72%, #ff8d2a) !important;
                border-radius: 3px;
                color: #fff;
        }
  //课程详情文字
  .detailFont{
     padding: 30px;
    color: rgb(5, 7, 59);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    font-size: 16px;
    white-space-collapse: preserve;
  }
    
.comments-container {
            .commentsItem {
                border-bottom: 1px solid rgb(232, 232, 232);
                margin-top: 10px;

                .comments-info {
                    display: flex;
                    justify-content: space-between;

                    div:first-of-type {
                        >img {
                            width: 32px;
                            height: 32px;
                            border-radius: 50%;
                            border: 1px solid;
                        }

                        span {
                            color: rgba(0, 0, 0, .65);
                            font-size: 14px;
                            padding: 0 10px;
                        }
                    }
                }

                .comments-content {
                    p:first-of-type {
                        padding-left: 40px;
                    }

                    div {
                        color: #999;
                        text-align: right;
                        font-size: 14px;

                        .remark-date {
                            margin-right: 5px;
                        }

                        span {
                            color: #777;
                        }
                    }
                }
            }
        }

//评级的svg图
.star-level {
    display: flex;
    align-items: center;
    margin-bottom: 20px;

    >svg {
        margin-right: 5px;
    }
}
.comment-reply {
    border-left: 2px solid #ddd;
    padding-left: 10px;
    margin-left: 50px;
}

</style>